//
//  DetailOfNumTableViewCell.m
//  LoveOfPet
//
//  Created by 芦彬 on 15/11/19.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "DetailOfNumTableViewCell.h"
#import "LuBDefine.h"
#import "DetailOfUserView.h"
#import "SDWebImageManager.h"
#import "UIImageView+WebCache.h"

@implementation DetailOfNumTableViewCell

- (void)dealloc{
    [_detailOfNu_list release];
    [_photo_desLabel release];
    [_photoImageView release];
    [_plnumLabel release];
    [_zanLabel release];
    [_list release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createDetailOfNumViewCell];
    }
    return self;
}

- (void)createDetailOfNumViewCell{
    self.selectionStyle = UITableViewCellSelectionStyleNone;

    self.photoImageView = [[UIImageView alloc] init];
    [self addSubview:_photoImageView];
    [_photoImageView release];
    
    self.photo_desLabel = [[UILabel alloc] init];
//    self.photo_desLabel.backgroundColor = [UIColor orangeColor];
    [self addSubview:_photo_desLabel];
    [_photo_desLabel release];
    
    self.plnumLabel = [[UILabel alloc] init];
//    self.plnumLabel.backgroundColor = [UIColor blueColor];
    [self addSubview:_plnumLabel];
    [_plnumLabel release];
    
    self.zanLabel = [[UILabel alloc] init];
//    self.zanLabel.backgroundColor = [UIColor magentaColor];
    [self addSubview:_zanLabel];
    [_zanLabel release];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat height = [[DetailOfUserView class] heightOfLabel:self.photo_desLabel.text andTextFont:[UIFont systemFontOfSize:14] withLabelWidths:CWIDTH - 20 - 20];
    
    self.photoImageView.frame = CGRectMake(30, 10, WIDTH - 20 - 20, HEIGHT - height - 70);
    self.photoImageView.layer.borderColor = [[UIColor orangeColor]CGColor];
    self.photoImageView.layer.borderWidth = 3;
    
    self.photo_desLabel.frame = CGRectMake(30, HEIGHT - height - 55, WIDTH - 20 - 20, height + 10);
    self.photo_desLabel.font = [UIFont systemFontOfSize:14];
    self.photo_desLabel.textColor = [UIColor grayColor];
    self.photo_desLabel.numberOfLines = 0;
    
    self.plnumLabel.frame = CGRectMake( 30 +WIDTH / 2, HEIGHT - 40, WIDTH / 5 - 20, 30);
    self.plnumLabel.textColor = [UIColor grayColor];
    self.plnumLabel.textAlignment = NSTextAlignmentRight;
    self.plnumLabel.font = [UIFont systemFontOfSize:13];
    
    self.zanLabel.frame = CGRectMake(30 + WIDTH / 2 + self.plnumLabel.frame.size.width + 30,HEIGHT - 40, WIDTH / 5 - 20, 30);
    self.zanLabel.textColor = [UIColor redColor];
    self.zanLabel.textAlignment = NSTextAlignmentRight;
    self.zanLabel.font = [UIFont systemFontOfSize:13];

    UILabel *pointLabel = [[UILabel alloc]initWithFrame:CGRectMake(5 + 2, 30, 10, 10)];
    pointLabel.backgroundColor = [UIColor orangeColor];
    pointLabel.textColor = [UIColor whiteColor];
    pointLabel.layer.masksToBounds = YES;
    pointLabel.layer.cornerRadius = 5;
    [self addSubview:pointLabel];
    [pointLabel release];

    UIImageView * timerView = [[UIImageView alloc]initWithFrame:CGRectMake(5 + 12, 30 - 4, 20, 20)];
    timerView.image = [UIImage imageNamed:@"LBtimer"];
    [self addSubview:timerView];
    [timerView release];
}

- (void)setList:(List *)list{
    if (_list != list) {
        [_list release];
        _list = [list retain];
    }
    
    NSURL *photoUrl = [NSURL URLWithString:list.photo];
    [self.photoImageView sd_setImageWithURL:photoUrl placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    self.photo_desLabel.text = list.photo_des;
    self.plnumLabel.text =[NSString stringWithFormat:@"💬 : %@", list.plnum];
    self.zanLabel.text =[NSString stringWithFormat:@"👍 : %@", list.zan];
    
    self.photoHeight = [list.picHeight floatValue];
    self.photoWidth = [list.picWidth floatValue];

    
    CGFloat height = [[DetailOfUserView class] heightOfLabel:self.photo_desLabel.text andTextFont:[UIFont systemFontOfSize:14] withLabelWidths:CWIDTH - 20 - 20];
    [self.delegate returnPhoto_desLabelOfHeight:height];
    
    
}
+ (DetailOfNumTableViewCell *)detailOfNumTableViewCellWithTableView:(UITableView *)tableView{
    static NSString *detailOfNumCell = @"detailOfNumCell";
    DetailOfNumTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:detailOfNumCell];
    if (!cell) {
        cell = [[[DetailOfNumTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:detailOfNumCell] autorelease];
    }
    return cell;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
